<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/10/29
 * Time: 下午8:29
 */

class RetainSourceService extends Service {

    public static function indexHeader($userType){
        $header = array(
            'RecDate'   => array('text' => PubFunc::t('日期')),
            'SID'   => array('text' => PubFunc::t('服')),
            'User'      => array('text' => $userType),
            'RemainDay1'   => array('text' => PubFunc::t('1日留存率')),
            'RemainDay7'   => array('text' => PubFunc::t('前7日留存率')),
            'RemainDay14'   => array('text' => PubFunc::t('前14日留存率')),
            'RemainDay21'   => array('text' => PubFunc::t('前21日留存率')),
        );

        return $header;
    }

    public static function indexData($params){

        $data = ModRetain::SourceData($params);
        foreach($data as &$v){
            $v['User'] = $v['KPIValue'];
                for($i=1; $i<31; $i++){
                    if(!empty($v['RemainDay'.$i])){
                        $v['RemainDay'.$i] = "{$v['RemainDay'.$i]}(<span style='color:green;'>".number_format($v['RemainDay'.$i] / $v['KPIValue'] * 100, 2, '.', '')."%</span>)";
                    }
                }
        }
        unset($v);

        return $data;
    }

} 